<!doctype html>
<html lang="zh-cn">

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <title>Login</title>
    <link rel="stylesheet" href="{{ url_for('static', filename = 'css/bootstrap.css') }}">
</head>

<body>
    <nav class="navbar navbar-expand-lg navbar-dark bg-primary">
        <a class="navbar-brand" href="/">{{ g.website_name }}</a>
    </nav>
    <div class="container mt-5">
        <form>
            <div class="form-group">
                <label for="username">Username</label>
                <input type="text" name="username" class="form-control" id="username" placeholder="Enter Username">
            </div>
            <div class="form-group">
                <label for="password">Password</label>
                <input type="password" name="password" class="form-control" id="password" placeholder="Enter Password">
            </div>
            <button type="button" class="btn btn-primary" onclick="login()">Login</button>
        </form>
    </div>
    <script src="{{ url_for('static', filename='js/jquery.js') }}"></script>
    <script src="{{ url_for('static', filename='js/popper.js') }}"></script>
    <script src="{{ url_for('static', filename='js/bootstrap.js') }}"></script>
    <script>
        var login = function () {
            var username = $('#username').val();
            var password = $('#password').val();
            if(username == '') {
                alert('Username is empty!');
                return;
            }
            if(password == '') {
                alert('Password is empty');
                return;
            }
            $.post('/login', {
                username: username,
                password: password
            }, function(r) {
                var obj = JSON.parse(r);
                if(obj.success == 'true') {
                    window.location = '/';
                } else {
                    alert(obj.msg);
                }
            });
        }
    </script>
</body>

</html>